package com.tanhua.manage.controller;

import com.sun.org.apache.regexp.internal.RE;
import com.tanhua.manage.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("/manage")
public class UserController {

    @Autowired
    private UserService userService;

    /**
     * 接口名称：用户数据翻页
     * 接口路径：GET/manage/users
     */
    @GetMapping("users")
    public ResponseEntity<Object> findByPage(
            @RequestParam(defaultValue = "1") Integer page,
            @RequestParam(defaultValue = "10") Integer pagesize){
        return userService.findByPage(page,pagesize);
    }

    /**
     * 接口名称：用户基本资料
     * 接口路径：GET/manage/users/:userID
     */
    @GetMapping("users/{userId}")
    public ResponseEntity<Object> findById(@PathVariable("userId") Long userId){
        return userService.findById(userId);
    }

    /**
     * 接口名称：视频记录翻页
     * 接口路径：GET/manage/videos
     */
    @GetMapping("videos")
    public ResponseEntity<Object> videoList(Long uid,
            @RequestParam(defaultValue = "1") Integer page,
            @RequestParam(defaultValue = "10") Integer pagesize){
        return userService.videoList(uid,page,pagesize);
    }

   /**
     * 接口名称：动态分页
     * 接口路径：GET/manage/messages
    */

    @GetMapping("messages")
    public ResponseEntity<Object> findPublishList(Long uid,String state,
            @RequestParam(defaultValue = "1") Integer page,
            @RequestParam(defaultValue = "10") Integer pagesize){
        Integer satai=null;
        if ("''".equals(state)||"".equals(state)) {

        }else{
            if(state!=null){
            satai=Integer.valueOf(state);}
        }

        return userService.findPublishList(page,pagesize,uid,satai);
    }

    /**
     * 接口名称：动态详情
     * 接口路径：GET/manage/messages/:id
     */
    @GetMapping("/messages/{id}")
    public ResponseEntity<Object> findMovementsById(@PathVariable("id") String publishId){
        return userService.findMovementsById(publishId);
    }

    /**
     * 接口名称：评论列表翻页
     * 接口路径：GET/manage/messages/comments
     */
    @GetMapping("/messages/comments")
    public ResponseEntity<Object> findCommentsById(
            @RequestParam(defaultValue = "1")Integer page,
            @RequestParam(defaultValue = "10")Integer pagesize,
            @RequestParam(name = "messageID") String publishId){
        return userService.findCommentsById(publishId,page,pagesize);
    }
    /**
     * 接口名称：用户冻结操作
     * 接口路径：POST/manage/users/freeze
     */
    @PostMapping("/users/freeze")
    public ResponseEntity<Object> savefreeze(@RequestBody Map<String,Object> param){
        return userService.savefreeze(param);
    }
    /**
     * 接口名称：用户解冻操作
     * 接口路径：POST/manage/users/unfreeze
     */
    @PostMapping("/users/unfreeze")
    public ResponseEntity<Object> unfreeze(@RequestBody Map<String,Object> param){
        return userService.unfreeze(param);
    }
    /**
     * 接口名称：动态通过
     * 接口路径：POST/manage/messages/pass
     */
    @PostMapping("/messages/pass")
    public ResponseEntity<Object> publishPass(@RequestBody String[]id){

        return userService.publishPass(id);
    }
    /**
     * 接口名称：动态拒绝
     * 接口路径：POST/manage/messages/reject
     */
    @PostMapping("/messages/reject")
    public ResponseEntity<Object> publishUnPass(@RequestBody String[]id){

        return userService.publishUnPass(id);
    }
}

















